package util.file;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;



public class GZipFileUtils
{
	public static long getUncompressedSize(File f) throws IOException
	{		
		RandomAccessFile raf = new RandomAccessFile(f, "r");
		try
		{
			raf.seek(raf.length() - 4);
			
			int b4 = raf.read();
			int b3 = raf.read();
			int b2 = raf.read();
			int b1 = raf.read();
			int totalBytes = (int)( (b1 << 24) | (b2 << 16) + (b3 << 8) + b4);
			
			return totalBytes;
		}
		catch (Exception e)
		{
			throw new IOException(e);
		}
		finally
		{
			try {raf.close();} catch (Exception e) { }
		}		
	}
	
//	public static long getUncompressedSize(MultiProtocolFile f) throws IOException
//	{		
//		ISeekableDataIO raf = f.getRandomAccessFile("r");
//		try
//		{
//			raf.seek(raf.length() - 4);
//			
//			int b4 = raf.read();
//			int b3 = raf.read();
//			int b2 = raf.read();
//			int b1 = raf.read();
//			int totalBytes = (int)( (b1 << 24) | (b2 << 16) + (b3 << 8) + b4);
//			
//			return totalBytes;
//		}
//		catch (Exception e)
//		{
//			throw new IOException(e);
//		}
//		finally
//		{
//			try {raf.close();} catch (Exception e) { }
//		}		
//	}
	
}
